package com.zjl.paike2.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zjl.paike2.entity.StudentInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 学生信息Mapper接口
 */
@Mapper
public interface StudentInfoMapper extends BaseMapper<StudentInfo> {
    
    /**
     * 查询学生列表（关联班级表查询班级名称）
     */
    @Select("SELECT s.*, c.class_name FROM student_info s LEFT JOIN class_info c ON s.class_id = c.class_id")
    List<StudentInfo> selectStudentList();
    
    /**
     * 根据学号查询学生信息（关联班级表查询班级名称）
     */
    @Select("SELECT s.*, c.class_name FROM student_info s LEFT JOIN class_info c ON s.class_id = c.class_id WHERE s.stu_id = #{stuId}")
    StudentInfo selectStudentById(@Param("stuId") String stuId);
    
    /**
     * 条件查询学生列表（关联班级表查询班级名称）
     */
    @Select("<script>" +
            "SELECT s.*, c.class_name FROM student_info s " +
            "LEFT JOIN class_info c ON s.class_id = c.class_id " +
            "<where> " +
            "   <if test='stuName != null and stuName != \"\"'> " +
            "       AND s.stu_name LIKE CONCAT('%', #{stuName}, '%') " +
            "   </if> " +
            "   <if test='stuId != null and stuId != \"\"'> " +
            "       AND s.stu_id LIKE CONCAT('%', #{stuId}, '%') " +
            "   </if> " +
            "   <if test='classId != null and classId != \"\"'> " +
            "       AND s.class_id = #{classId} " +
            "   </if> " +
            "</where> " +
            "</script>")
    List<StudentInfo> selectStudentByCondition(@Param("stuName") String stuName, 
                                             @Param("stuId") String stuId, 
                                             @Param("classId") String classId);
} 